<template>
    <div class="swiper-container" ref="floor1Swiper">
        <div class="swiper-wrapper">
            <div
                class="swiper-slide"
                v-for="(item, index) in list"
                :key="item.id"
            >
                <img :src="item.imgUrl" />
            </div>
        </div>
        <!-- 如果需要分页器 -->
        <div class="swiper-pagination"></div>

        <!-- 如果需要导航按钮 -->
        <div class="swiper-button-prev"></div>
        <div class="swiper-button-next"></div>
    </div>
</template>

<script>
// 引入Swiper
import Swiper from "swiper"
export default {
    name: "Carousel",
    props: ["list"],
    watch: {
        list: {
            // 立即监听：不管数据有无变化
            immediate: true,
            handler() {
                // 只能监听数据已经有了，还是不能确定结构是否完整
                this.$nextTick(() => {
                    var mySwiper = new Swiper(this.$refs.floor1Swiper, {
                        loop: true,
                        // 分页器
                        pagination: {
                            el: ".swiper-pagination",
                            // 点击小圆点的时候也会切换图片
                            clickable: true,
                        },
                        navigation: {
                            nextEl: ".swiper-button-next",
                            prevEl: ".swiper-button-prev",
                        },
                    })
                })
            },
        },
    },
}
</script>

<style scoped>
</style>